<template>
  <div class="app-container">
    <el-form v-if="executeQuery" :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="id" prop="id">
        <el-input
          v-model="queryParams.id"
          placeholder="请输入id"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
       <el-form-item label="会员类型" prop="membertype">
      <el-select v-model="queryParams.membertype" placeholder="全部">
                      <el-option value="0" label="快递员"></el-option>
                      <el-option value="1" label="普通会员"></el-option>
                    </el-select>
       </el-form-item>
      <el-form-item label="创建时间" prop="time1">
        <el-date-picker
          v-model="queryParams.time1"
          type="daterange"
          value-format="yyyy-MM-dd"
          range-separator="至"
          start-placeholder="开始日期"
          end-placeholder="结束日期">
        </el-date-picker>
      </el-form-item>
       <el-form-item label="手机号" prop="phone">
        <el-input
          v-model="queryParams.phone"
          placeholder="请输入手机号"
        />
      </el-form-item>
      <el-form-item label="状态" prop="status">
      <el-select v-model="queryParams.status" placeholder="全部">
                      <el-option value="0" label="正常"></el-option>
                      <el-option value="1" label="已锁定"></el-option>
                    </el-select>
       </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
        <el-button type="text" @click="cancel1">取 消</el-button>
      </el-form-item>
    </el-form>
    <div class="flex-container">
    <el-button icon="el-icon-search"  @click="executeQuery =true" plain >高级搜索</el-button>
    </div>
    <el-row :gutter="10" class="mb8">
<!--      <el-col :span="1.5">-->
<!--        <el-button-->
<!--          type="primary"-->
<!--          plain-->
<!--          icon="el-icon-plus"-->
<!--          size="mini"-->
<!--          @click="handleAdd"-->
<!--          v-hasPermi="['finance:account:add']"-->
<!--        >新增</el-button>-->
<!--      </el-col>-->
<!--      <el-col :span="1.5">-->
<!--        <el-button-->
<!--          type="success"-->
<!--          plain-->
<!--          icon="el-icon-edit"-->
<!--          size="mini"-->
<!--          :disabled="single"-->
<!--          @click="handleUpdate"-->
<!--          v-hasPermi="['finance:account:edit']"-->
<!--        >修改</el-button>-->
<!--      </el-col>-->
<!--      <el-col :span="1.5">-->
<!--        <el-button-->
<!--          type="danger"-->
<!--          plain-->
<!--          icon="el-icon-delete"-->
<!--          size="mini"-->
<!--          :disabled="multiple"-->
<!--          @click="handleDelete"-->
<!--          v-hasPermi="['finance:account:remove']"-->
<!--        >删除</el-button>-->
<!--      </el-col>-->
<!--      <el-col :span="1.5">-->
<!--        <el-button-->
<!--          type="warning"-->
<!--          plain-->
<!--          icon="el-icon-download"-->
<!--          size="mini"-->
<!--          @click="handleExport"-->
<!--          v-hasPermi="['finance:account:export']"-->
<!--        >导出</el-button>-->
<!--      </el-col>-->
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="accountList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="id" align="center" prop="id" />
      <el-table-column label="会员类型" align="center" prop="membertype" >
          <template slot-scope="scope">
          {{ scope.row.membertype == 0? '快递员' : '普通会员' }}
          </template>
      </el-table-column>
       <el-table-column label="手机号" align="center" prop="phone" >
         <template slot-scope="scope">
           <span @click="handleDetail(scope.row)" style="color:#6a9eff;text-decoration: underline;">{{scope.row.phone}}</span>
         </template>
       </el-table-column>
      <el-table-column label="账户余额" align="center" prop="totalBalance" />
      <el-table-column label="可用余额" align="center" prop="availableBalance" />
      <el-table-column label="待收" align="center" prop="receivable" />
      <el-table-column label="冻结" align="center" prop="frozenAmount" />
      <el-table-column label="状态" align="center" prop="status" >
         <template slot-scope="scope">
          {{ scope.row.status == 0? '正常' :'锁定'}}
          </template>
      </el-table-column>
      <el-table-column label="创建时间" align="center" prop="createTime" />
      <el-table-column label="最近登陆时间" align="center" prop="latestTime" />
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
<!--          <el-button-->
<!--            size="mini"-->
<!--            type="text"-->
<!--            icon="el-icon-edit"-->
<!--            @click="handleUpdate(scope.row)"-->
<!--            v-hasPermi="['finance:account:edit']"-->
<!--          >修改</el-button>-->
          <span class="ellipsis" @click="toggleButton"><strong>···</strong></span><br/>
          <el-button v-show="showButton" @click="editStatus1(scope.row)" icon="el-icon-lock" type="text" plain style="color: red">锁定</el-button><br/>
           <el-button v-show="showButton" @click="editStatus2(scope.row)" icon="el-icon-unlock" type="text" plain style="color: blue">解锁</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改账户信息对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="账户余额" prop="totalBalance">
          <el-input v-model="form.totalBalance" placeholder="请输入账户余额" />
        </el-form-item>
        <el-form-item label="可用余额" prop="availableBalance">
          <el-input v-model="form.availableBalance" placeholder="请输入可用余额" />
        </el-form-item>
        <el-form-item label="待收" prop="receivable">
          <el-input v-model="form.receivable" placeholder="请输入待收" />
        </el-form-item>
        <el-form-item label="冻结" prop="frozenAmount">
          <el-input v-model="form.frozenAmount" placeholder="请输入冻结" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>

     <!-- 修改账户信息状态对话框 -->
    <el-dialog :title="title" :visible.sync="open1" width="300px" append-to-body>
       <span><i class="el-icon-warning"></i>你确定要将{{phone}}的账户锁定/解散吗？</span>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm2">确 定</el-button>
        <el-button @click="cancel2">取 消</el-button>
      </div>
    </el-dialog>

    <el-dialog :title="title" :visible.sync="open2" width="300px" append-to-body>
      <span><i class="el-icon-warning"></i>你确定要将{{phone}}的账户锁定/解散吗？</span>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm3">确 定</el-button>
        <el-button @click="cancel3">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listAccount, getAccount, delAccount, addAccount, updateAccount,updateStatus1,updateStatus2 } from "@/api/finance/account";

export default {
  name: "Account",
  data() {
    return {
      showButton:false,
      phone:"",
      id:"",
      staus:"",
     executeQuery:false,
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 账户信息表格数据
      accountList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      open1:false,
      open2:false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        id: null,
        type: null,
        status: null,
        createTime:null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      }
    };
  },
  // 不能为空判断 totalBalance: [
  //           { required: true, message: '请输入活动名称', trigger: 'blur' },
  //           { min: 3, max: 5, message: '长度在 3 到 5 个字符', trigger: 'blur' }
  //         ],
  created() {
    this.getList();
  },
  methods: {
    toggleButton() {
      this.showButton =!this.showButton;
    },
    handleDetail(row) {
      const id=row.id
      this.$router.push({path:"/personnel/courier-data/index/"+id})
    },
    editStatus1(row){
       this.reset();
      this.phone= row.phone;
      this.id= row.id;
      this.status=row.status;
     this.open1 = true;
     this.title = "提示";

    },
    editStatus2(row){
      this.reset();
      this.phone= row.phone;
      this.id= row.id;
      this.status=row.status;
      this.open2 = true;
      this.title = "提示";

    },
    submitForm2(){
        updateStatus1(this.id).then(response => {
          this.$modal.msgSuccess("修改成功");
          this.open1 = false;
          this.getList();
        });
    },
    submitForm3(){
        updateStatus2(this.id).then(response => {
          this.$modal.msgSuccess("修改成功");
          this.open2 = false;
          this.getList();
        });
    },

    /** 查询账户信息列表 */
    getList() {
      this.loading = true;
      listAccount(this.queryParams).then(response => {
        this.accountList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },

    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    cancel1() {
      this.executeQuery = false;
      this.reset();
    },
     cancel2() {
      this.open1 = false;
      this.reset();
    },
    cancel3() {
      this.open2 = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        type: null,
        totalBalance: null,
        availableBalance: null,
        receivable: null,
        frozenAmount: null,
        status: null,
        cid: null,
        did: null,
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      if(this.queryParams.time1!=null){
        const time1=this.queryParams.time1;
        this.queryParams.start=time1[0];
        this.queryParams.end=time1[1];
      }else{
        this.queryParams.start=null;
        this.queryParams.end=null;
      }
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加账户信息";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getAccount(id).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改账户信息";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateAccount(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addAccount(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal.confirm('是否确认删除账户信息编号为"' + ids + '"的数据项？').then(function() {
        return delAccount(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('finance/account/export', {
        ...this.queryParams
      }, `account_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>

<style scoped>
.flex-container {
  display: flex;
  justify-content: center;
}
</style>
